﻿<script src="~/Scripts/jquery-3.4.1.js"></script>
@* 样式 *@
<style>
    .box > div {
        display: flex;
        /*height:30px;*/
        margin: 10px 10px;
        align-items: center;
    }

        .box > div > div {
            width: 70px;
        }

    .box input, .box select {
        width: 170px;
        margin-right: 30px;
    }

    #myModal2 .form-group {
        display: flex;
        align-items: center;
        justify-content: center;
    }

        #myModal2 .form-group > div {
            width: 70px;
        }
</style>
@* 主体 *@
<div class="row" style="width:100%;background-color:dimgray;padding:20px;margin:0">
    <div class="col-md-3"><h2 style="margin:0;color:#fff">仓储管理系统</h2></div>
    <div class="col-md-6"></div>
    <div class="col-md-3 dropdown ">
        <button type="button" class="btn dropdown-toggle" id="menu" data-toggle="dropdown">
            <span class="glyphicon glyphicon-user"></span>&nbsp;
            当前登录&nbsp;
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" aria-labelledby="menu">
            @{ var user = (Session["user"] as StorageApi.Models.Admin);}
            <li><a href="javascript:;" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-user"></span> &nbsp;&nbsp;@(user.UserName)</a></li>
            <li><a href="javascript:;" data-toggle="modal" data-target="#myModal2"><span class="glyphicon glyphicon-wrench"></span> &nbsp;&nbsp;修改密码</a></li>
            <li><a href="javascript:;" onclick="exit()" id="exit"><span class="glyphicon glyphicon-log-out"></span> &nbsp;&nbsp;退出系统</a></li>
        </ul>
    </div>
</div>

<!--  用户信息修改 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form action="/Home/updata" method="post" id="myForm">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">编辑用户</h4>
                </div>
                <div class="modal-body box">
                    <div>
                        <div>用户编号</div><input type="text" class="form-control" name="UserCode" disabled value="@(user.UserCode)" />
                        <div>用户名</div><input type="text" class="form-control" name="UserCode" disabled value="@(user.UserName)" />
                    </div>
                    <div>
                        <div>真名</div><input type="text" class="form-control" name="RealName" value="@(user.RealName)" />
                        <div>Email</div><input type="text" class="form-control" name="Email" id="Email" value="@(user.Email)" />
                    </div>
                    <div>
                        <div>电话</div><input type="text" class="form-control" id="Mobile" name="Mobile" value="@(user.Mobile)" />
                        <div>手机</div><input type="text" class="form-control" id="Phone" name="Phone" value="@(user.Phone)" />
                    </div>
                    <div>
                        <div>部门</div>
                        <select disabled class="form-control" name="DepartNum">
                            <option value="0">请选择部门</option>
                            @foreach (var item in ViewBag.dep)
                            {
                                if ((user.DepartNum) == item.DepartNum)
                                {
                                    <option selected value="@item.DepartNum">@item.DepartName</option>
                                }
                                else
                                {
                                    <option value="@item.DepartNum">@item.DepartName</option>
                                }
                            }

                        </select>


                        <div>角色</div>

                        <select disabled class="form-control" name="RoleNum">
                            <option value="0">请选择角色</option>
                            @foreach (var item in ViewBag.adminlist)
                            {
                                if ((user.RoleNum) == item.RoleNum)
                                {
                                    <option selected value="@item.RoleNum">@item.RoleName</option>
                                }
                                else
                                {
                                    <option value="@item.RoleNum">@item.RoleName</option>
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">确定</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </form>
</div>

<!-- 修改密码 模态框（Modal） -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel2">修改密码</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <div>旧密码：</div>
                    <input type="password" class="form-control" name="pwd" value="" id="jiuPwd" />
                </div>
                <div class="form-group">
                    <div>新密码：</div>
                    <input type="password" class="form-control" name="pwd1" value="" id="xinPwd" />
                </div>
                <div class="form-group">
                    <div>重复密码：</div>
                    <input type="password" class="form-control" name="pwd2" value="" id="chonPwd" />
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="updata">修改</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

@* js代码 *@
<script>
    function exit() {
        if (confirm("确认退出系统吗？")) {
            window.location = "/home/exit"
        }
    }
    $(function () {
        $("#myForm").submit(function () {
            var falg = true;
            var zhengzeEmail = /^\w+([-+.]\w+)*@@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            var Email = $("#Email").val();
            if (Email != "") {
                if (!zhengzeEmail.test(Email)) {
                    alert("邮箱格式错误")
                    falg = false;
                }

            }
            if (falg) {
                var zhengzeMobile = /^\d{3}-\d{8}|\d{4}-\d{7}$/;
                var Mobile = $("#Mobile").val();

                if (Mobile != "") {
                    if (!zhengzeMobile.test(Mobile)) {
                        alert("电话格式错误")
                        falg = false;
                    }
                }
            }
            if (falg) {
                var zhengzePhone = /^1[3,5,6,8]\d{9}$/;
                var Phone = $("#Phone").val();
                if (Phone != "") {
                    if (!zhengzePhone.test(Phone)) {
                        alert("手机格式错误")
                        falg = false;
                    }
                }
            }

            return falg;

        })
        $("#updata").click(function () {
            var jiu = $("#jiuPwd").val();
            var xin = $("#xinPwd").val();
            var chon = $("#chonPwd").val();
            if (jiu == "" || xin == "" || chon == "") {
                alert("密码不能为空！");
            }
            else if (chon != xin) {
                alert("两次密码不一致！");
            }
            else {
                $.ajax({
                    url: "/home/upPwd?jiuPwd=" + jiu + "&xinPwd=" + xin,
                    type: "post"
                }).then(res => {
                    if (res > 0) {
                        alert("修改成功！")
                        window.location = "/admin/index"
                    } else {
                        alert("旧密码错误！")
                    }
                })

            }
        })
    })
</script>